<template>
    <!-- 保养待处理 -->
    <div class="layout-padding">
      <basic-container class="layout-padding-auto layout-padding-view">
        <avue-crud
            ref="crud"
            :page="page"
            :data="tableData"
            :permission="permissionList"
            :table-loading="tableLoading"
            :option="tableOption"
            @on-load="getList"
            @search-change="searchChange"
            @refresh-change="refreshChange"
            @size-change="sizeChange"
            @current-change="currentChange"
            @row-del="rowDel"
        >
          <template #menu-left>
  <!--            <el-button-->
  <!--                v-if='permissions.om_omrepairpending_export'-->
  <!--                class="filter-item"-->
  <!--                plain-->
  <!--                type="primary"-->
  <!--                icon="el-icon-download"-->
  <!--                @click="exportExcel">导出-->
  <!--          </el-button>-->
          </template>
          <template #eventStatus="{ row }">
             <el-tag v-if="row.eventStatus === '6'">未指派</el-tag>
            <el-tag v-if="row.eventStatus === '0'">待处理</el-tag>
            <el-tag type='warning' v-if="row.eventStatus === '1'">处理中</el-tag>
            <el-tag type='success' v-if="row.eventStatus === '2'">已处理</el-tag>
            <el-tag type='success' v-if="row.eventStatus === '3'">转工单</el-tag>
            <el-tag type='info' v-if="row.eventStatus === '4'">事件关闭</el-tag>
            <el-tag type='success' v-if="row.eventStatus === '5'">已评价</el-tag>
            <el-tag type='success' v-if="row.eventStatus === '7'">已取消</el-tag>
          </template>
          <template #menu="scope">
            <!-- v-if='permissions.om_omrepairpending_controls' -->
            <el-button
                
                :disabled="
                scope.row.eventStatus === '2'
  
              "
                size="mini"
                type='primary'
                text
                icon="el-icon-mouse"
                @click="handleItem(scope.row, scope.index)"
            >转工单
            </el-button>
            <!-- v-if='permissions.om_omrepairpending_controls' -->
            <el-button
                
                :disabled="
                scope.row.eventStatus === '1'
  
              "
                type='primary'
                text
                size="mini"
                icon="el-icon-user"
                @click="handleOrder(scope.row, scope.index)"
            >关闭
            </el-button>
            <!-- v-if='permissions.om_omrepairpending_controls' -->
            <el-button
               
                :disabled="
                scope.row.eventStatus === '4'
              "
                type='primary'
                text
                size="mini"
                icon="el-icon-chat-line-square"
                @click="handleWait(scope.row, scope.index)"
            >取消
            </el-button>
          </template>
        </avue-crud>
      </basic-container>
    </div>
  </template>
  
  <script>
  import {
    fetchEventList,
    delObj,
    operaEvent,
  } from '/@/api/maintenance/upkeep/event'
  import {tableOption} from '/@/const/crud/maintenance/upkeep/pending'
//   import {mapGetters} from 'vuex'
  
  export default {
    name: 'omworder',
    data() {
      return {
        searchForm: {},
        tableData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableLoading: false,
        tableOption: tableOption
      }
    },
  
    computed: {
    //   ...mapGetters(['permissions', 'userInfo']),
      permissionList() {
        return {
        //   getBtn: this.validData(this.permissions.om_omrepairpending_get, false),
        }
      }
    },
    watch: {},
    methods: {
      getList(page, params) {
        this.tableLoading = true
        fetchEventList(
            Object.assign(
                {
                  current: page.currentPage,
                  size: page.pageSize,
                  // handleUserId: this.userInfo.userId
                  // eventStatus: 1
                },
                params,
                this.searchForm
            )
        )
            .then((response) => {
              this.tableData = response.data.records
              this.page.total = response.data.total
              this.tableLoading = false
            })
            .catch(() => {
              this.tableLoading = false
            })
      },
      rowDel: function (row, index) {
        this.$confirm('是否确认删除ID为' + row.orId, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
            .then(function () {
              return delObj(row.orId)
            })
            .then((data) => {
              this.$message.success('删除成功')
              this.getList(this.page)
            })
            .catch((cancelorerror) => {
            })
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize
      },
      currentChange(current) {
        this.page.currentPage = current
      },
      searchChange(form, done) {
        this.searchForm = form
        this.page.currentPage = 1
        this.getList(this.page, form)
        done()
      },
      refreshChange() {
        this.getList(this.page)
      },
      handleItem(row) {
        this.$confirm('是否确认转工单', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          operaEvent({eventNo: row.eventNo, eventStatus: 3 + ''}).then((res) => {
            this.$message.success('转工单成功')
            this.getList(this.page)
          })
        })
      },
      handleOrder(row) {
        this.$confirm('是否确认关闭', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          operaEvent({eventNo: row.eventNo, eventStatus: 4 + ''}).then((res) => {
            this.$message.success('关闭成功')
            this.getList(this.page)
            // this.getCount()
          })
        })
      },
      handleWait(row) {
        this.$confirm('是否确认取消工单', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          operaEvent({eventNo: row.eventNo, eventStatus: 7 + ''}).then((res) => {
            this.$message.success('取消工单成功')
            this.getList(this.page)
          })
        })
      },
      handleActive(row) {
        // this.$confirm('是否确认确认激活', '提示', {
        //   confirmButtonText: '确定',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        // }).then(() => {
        //   operaEvent({orderNo: row.orderNo, eventStatus: 11 + ''}).then((res) => {
        //     this.$message.success('激活成功')
        //     this.getList(this.page)
        //   })
        // })
      },
      // 导出
      exportExcel() {
        this.downBlobFile('/om/omrepairmodel/export', this.searchForm, '设备维修模版.xlsx')
      },
      getCount() {
        // getOrderCount({ handleUserId: this.userInfo.userId }).then((res) => {
        //   let list = res.data.data
        //   this.$store.commit('setOrderCount', list.orderCount)
        //   this.$store.commit('setComplainCount', list.complainCount)
        // })
      }
    }
  }
  </script>
  